<template>
	<view class="page-body">
        <view class="logo">
			<view class="img">
				
			</view>
		</view>
		<!-- 账号密码输入框 -->
		<view class="form">
			<view class="code">
				<view class="flex0 input-left">手机号</view>
				<input placeholder="请输入手机号" v-model="phoneNumber" placeholder-style="color: #929292;" style="width: 100%;" maxlength="11" />
			</view>
			<view class="input-row password">
				<view class="flex0 input-left">密码</view>
				<input :type="inputType" placeholder="请输入密码" @input="bindpwd" placeholder-style="color:#929292" maxlength="16" />
				<view @click.stop="showPwd" class="pwd-eyes">
					<img src="/static/img/icon/eyes.png" alt="" class="uni-icon-eye" v-if="inputType=='password'" >
					<img src="/static/img/icon/eyes_on.png" alt="" class="uni-icon-eye" v-else >
				</view>
			</view>
			<view class="p-right">
				<navigator url="/pages/user/setting/password/forgetpwd" class="r-text">忘记密码</navigator>
			</view>
			<view class="btn" @tap="doLogin">登 录</view>
			<view class="flex protocol"> <text @click="goReg">去注册>> </text></view>
			
		</view>
	</view>
</template>

<script>
	var that;
	import {isPoneAvailable,TimeStorage} from '@/utils/utils.js';
	import {
	    mapState,
	    mapMutations
	} from 'vuex'	
	export default {
		data() {
			return {
				phoneNumber: '',
				passwd:'',
				inputType:"password",
			}
		},
		onShow() {
			if(this.usermobile!=''){
				this.phoneNumber = this.usermobile
			}
		},
		onLoad() {
			that = this;
		}, 
		computed:mapState({
			usermobile(state){
				return state.usermobile
			}
		}),
		methods: {
			...mapMutations(['setusermobile','login']),
			bindpwd(e){
				let value = e.detail.value;
				this.passwd = value;
			},
			showPwd(){
				if(this.inputType=="password"){
					this.inputType="text"
				}else{
					this.inputType="password"
				}
			},
			doLogin(){
				uni.hideKeyboard();
				//验证手机号码
				if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phoneNumber))){ 
					uni.showToast({title: '请填写正确手机号码',icon:"none"});
					return false; 
				}
				if(this.passwd==""){
					this.$showToast('请填写登录密码')
					return;
				}
				
				this.$https.POST({
					url:'/public/telLogin',
					data:{
						mobile:that.phoneNumber,
						pwd:that.passwd
					},
					success(res){
						let data=res.data;
						data.usermobile = that.phoneNumber
						that.setusermobile(that.phoneNumber)
						that.login(data)
						uni.showToast({
							title:res.message,
							icon:"none",
						})
						// data.isNewUser = true
						// if(data.isNewUser){
						// 	uni.$emit('register',data)
						// }
						uni.switchTab({
							url:"/pages/tabBar/home/home"
						})
					}
				})
			},
			goReg(){
				uni.redirectTo({
					url:"/pages/login/register"
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "../../static/css/login.scss";
	
	.p-right{
		text-align: right;
		.r-text{
			display: inline-block;color: #f23d3d;
		}
	}
	.protocol{
		line-height: 60upx;
		justify-content:center;
		text{color: $color2;}
	}
</style>
